package gi18n_lang

import (
	"context"
	"errors"
	"strings"
	"video-api/api/v1"
	"video-api/internal/service"
)

type langController struct{}

var LangHandle = new(langController)

func (l *langController) LangSwitch(ctx context.Context, req *v1.LangSwitchReq) (res *v1.LangSwitchRes, err error) {
	lang := req.Lang
	langSwitch, err := service.LangService().LangSwitch(ctx, lang)
	res = new(v1.LangSwitchRes)
	res.Info = langSwitch
	return
}

func (l *langController) WriteLangFile(ctx context.Context, req *v1.WriteLangReq) (res *v1.LangSwitchRes, err error) {
	if strings.Trim(req.Signature, " ") == "" || strings.Trim(req.Timestamp, " ") == "" {
		return nil, errors.New("Signature或Timestamp为空")
	}
	err = service.LangService().WriteLangFile(ctx, req)
	return
}
